function stOut=modeFinderCsminwel(xzero,estimopt,...
    parStru,posStru,model,dataStru,prpar,prss,filterStru,flags,struIn)
%
%% Inputs 
%
% xZero             (vector)    Initial guess for the estimated parameter *untransformed*
%
% estimopt          (structure) Options for estimation 
%
% All remaining inputs are the same as in *modePosteriorMin.m*. See that function for details 
% must include 
% struIn.transMat   Transformation matrix to go from original parameter to
%                   min 
%
%% Output 
% stOut.LPosterior 
% stOut.mode 
% stOut.exitFlag
% stOut.iterations 
% stOut.Hessian
% stOut.time 
% stOut.info

%% Notes 
% Uses *modePosteriorMin.m* for evaluation of the posterior 
% When called from the Parallel Loop Uses silent csminwel
%
tic;

%% 1. Assign default values
stOut.LPosterior=inf;
stOut.mode=nan(length(xzero),1);
stOut.iterations=-1;
stOut.exitFlag=-10;
stOut.tiempo=0; 
stOut.Hessian=nan(length(xzero)); 
stOut.info={'Problems at start'}; 

%% 2. Transform XZERO into XZEROMIN, return if any value is imaginary
if flags.transform==1
    xzeromin=feval(@mod2min,xzero,struIn.transMat);
    if any( imag(xzeromin) ) || any( isnan(xzeromin) )
        disp('Imaginary Starting Value')
        return
    end
end 
funcSubOptim=filterStru.funcMin;
if flags.parallel==0
    funcOptim=@csminwel;
else
    funcOptim=@csminwel_silent;
end

disp('Starting Density'); 
[logpost2]=...
    feval(filterStru.funcMin,xzeromin,...
    parStru,posStru,model,dataStru,prpar,prss,filterStru,flags,struIn);
fprintf('LogPosterior=%5.5e \n',-logpost2);
%% 3. Call CSMINWEL
% modePosteriorOpt(parest,parStru,posStru,model,dataStru,prpar,prss,filterStru,flags,struIn)
[stOut.LPosterior,xestmin,~,stOut.Hessian,stOut.iterations,~,stOut.exitFlag]=...
    feval(funcOptim,funcSubOptim,xzeromin,0.25*eye(length(xzeromin)),[],...
    estimopt.TolFun,estimopt.MaxIter,...
    parStru,posStru,model,dataStru,prpar,prss,filterStru,flags,struIn); 

%% 4. Retrive stOut.mode, return if any value nan or imaginart
stOut.mode=feval(@min2mod,xestmin,struIn.transMat);
if any( imag(stOut.mode) ) || any( isnan(stOut.mode) )
    stOut.LPosterior=inf;
    stOut.mode=nan(length(xzero),1);
end
stOut.time=toc;